package com.lw.ssm.task;

import com.lw.ssm.event.StudentEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author Administrator
 * @version 1.0
 * @description:
 * @date 2022/3/12 9:13
 */
@Component
@EnableScheduling
public class MyJob {

    public ApplicationContext context;

    @Autowired
    public void setContext(ApplicationContext context) {
        this.context = context;
    }

    @Scheduled(cron = "0/10 * * * * ?")
    public void job1(){
        System.out.println("更新缓存了");
        context.publishEvent(new StudentEvent());
    }
}
